class Solution {
public:
    vector<int> resultsArray(vector<int>& nums, int k) {
        int n=nums.size();
        vector<int> result(n-k+1, -1);
        for (int i = 0; i<n-k+1; ++i) {
            bool isValid = true;
            for (int j = 1; j < k; ++j) {
                if (nums[i+j]-nums[i+j-1] != 1) {
                    isValid = false;
                    break;
                }
            }
            if (isValid) {
                result[i] = nums[i+k-1];
            }
        }
        return result;
    }
};

class Solution {
public:
    vector<int> resultsArray(vector<int>& nums, int k) {
        int n = nums.size();
        vector<int> res(n-k+1,-1);
        int cnt = 0;
        for (int i = 0; i<n; ++i) {
            if (i != 0 && nums[i]-nums[i-1] != 1) {
                cnt = 1;
            } else {
                ++cnt;
            }
            if (cnt >= k) {
                res[i-k+1] = nums[i];
            }
        }
        return res;
    }
};